/**
 * Created by JasonChou on 16/6/6.
 */

import http from '../libs/http'
import promise from '../libs/promise'

export default {
  login(phone, password, country){

  },
  loginByThreeParty(openId){

  },
  register({phone, password, captcha, country}){
    var conditions = {};

    conditions.phone = phone;
    conditions.password = password;
    conditions.captcha = captcha;

    if (country)
      conditions.country = country;

    return http.post({
      url: api + 'new/users/regsiter',
      data: conditions
    })
  },
  autoLogin(){
    return http.get({
      url: api + 'new/login',
    }).then(function (obj) {
      if (obj.code === 0) {
        if (obj.data.userInfo.sector == 30) {
          obj.data.userInfo.topBanner = obj.data.storeInfo.topBanner || '/static/img/bg_user.png';
          obj.data.userInfo.like = obj.data.storeInfo.like;
          obj.data.userInfo.realName = obj.data.userInfo.v;
          obj.data.userInfo.handicraft = obj.data.userInfo.handicraft_v;
        }
      }

      return obj;
    })
  },

  getUserInfo(userId){
    return http.get({
      url: api + 'new/users',
      data: {userId: userId, isFollow: 1}
    }).then(function (obj) {
      if (obj.code === 0) {
        if (!obj.data.topBanner)
          obj.data.topBanner = '/static/img/bg_user.png';

        if (obj.data.companyId) {
          obj.data.company['_id'] = obj.data.companyId;
        }

        obj.data.realName = obj.data.v;
        obj.data.handicraft = obj.data.handicraft_v;
      }

      return obj;
    })
  }
}
